package com.yang.seckillsys.controller;


import com.yang.seckillsys.pojo.User;
import com.yang.seckillsys.service.impl.UserServiceImpl;
import com.yang.seckillsys.utils.MD5Util;
import com.yang.seckillsys.vo.LoginVo;
import com.yang.seckillsys.vo.RespBean;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author YANGLIYUAN
 * @since 2021-04-12
 */
@Controller
@RequestMapping("/user")
@Slf4j
public class UserController {
    @Autowired
    private UserServiceImpl userService;

    @RequestMapping("/toRegister")
    public String register(){
       return "register";
    }

    @RequestMapping("/doRegister")
    @ResponseBody
    public  RespBean register(@Valid LoginVo loginVo , HttpServletRequest request, HttpServletResponse response){
        log.info(loginVo.getMobile()+":"+loginVo.getPassword());
        User user = new User();
        user.setNickname(loginVo.getMobile());
        String pass = MD5Util.formPassToDBPass(loginVo.getPassword(), MD5Util.salt);
        user.setPassword(pass);
        user.setSlat(MD5Util.salt);
        return userService.addUser(user);
/*
        User user1 = new User();
        user1.setNickname(loginVo.getMobile());
        String dbPass = MD5Util.formPassToDBPass(loginVo.getPassword(), MD5Util.salt);
        user1.setPassword(dbPass);
        user1.setSlat(MD5Util.salt);
        if( userService.save(user1)){
            return RespBean.success(RespBeanEnum.SUCCESS);
        }
        return RespBean.success(RespBeanEnum.REGISTER_ERROR);*/
    }

}
